<template>
  <div>
    <div class="table-body">
      <el-table :data="tableData" border v-loading="isLoading" style="width: 100%">
        <el-table-column prop="ufModule" label="模块"></el-table-column>
        <el-table-column prop="ufName" label="功能"></el-table-column>
        <el-table-column fixed="right" label="操作" width="220">
          <template slot-scope="scope">
            <el-button
              @click="handleClick(scope.row)"
              size="small"
              v-if="isPermissionsBtn('wxSetting_open')"
              type="primary"
            >{{scope.row.ufIsOpen == 1 ? '开启' : '关闭'}}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @current-change="currentPageChange"
          layout="prev, pager, next"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
export default {
  name: "",
  data() {
    return {
      tableData: [],
      isLoading: false,
      total: 1,
      param: {
        data: {
        },
        queryRequest: {
          page: 1,
          size: 10
        }
      }
    };
  },
  components: {},
  computed: {
    ...mapGetters(["isPermissionsBtn"])
  },
  beforeMount() {},
  mounted() {
    this.initData();
  },
  methods: {
    initData() {
        this.isLoading = true;
      this.$service.findUserFunction(this.param).then(res => {
        if (res.code == "00000") {
            this.isLoading = false;
          if (
            res.data.length == 0 &&
            this.param.queryRequest.pageNum != 1
          ) {
            this.param.queryRequest.pageNum -= 1;
            this.initData();
          }
          this.tableData = (res.data) || [];
          this.total = res.data.total || 0;
        }
      });
    },
    handleClick(scope) {
          if (scope.ufIsOpen == '1') {
          var param ={
              id:scope.id,
              ufIsOpen:"0"
          }
          this.$service.updateIsOpenById(param).then(res => {
            if (res.code == "00000") {
              this.$message({
                message: "开启成功",
                type: "success"
              });
              this.initData();
            } else {
              this.$message({
                message: res.message,
                type: "warning"
              });
            }
          });
        } else {
            var param ={
              id:scope.id,
              ufIsOpen:"1"
          }
          this.$service.updateIsOpenById(param).then(res => {
            if (res.code == "00000") {
              this.$message({
                message: "关闭成功",
                type: "success"
              });
              this.initData();
            } else {
              this.$message({
                message: res.message,
                type: "warning"
              });
            }
          });
        }
    },
    currentPageChange(e) {}
  },
  watch: {}
};
</script>
<style scoped>
</style>